package com.esri.core.internal.tasks.oauth;

import com.esri.core.internal.io.handler.h;
import com.esri.core.internal.io.handler.n;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.EsriServiceException;
import com.sangfor.ssl.service.utils.IGeneral;
import java.util.Map;
import org.codehaus.jackson.JsonParser;

/* loaded from: classes.dex */
public class a extends com.esri.core.internal.tasks.d<e> {
    private static final long serialVersionUID = 1;

    public a(GetTokenTaskParameters getTokenTaskParameters, String str) {
        super(getTokenTaskParameters, a(str), null);
        if (!getTokenTaskParameters.validate()) {
            throw new EsriServiceException("At least one parameter is missing or incorrect. App secret must be set for application logins. ");
        }
    }

    public a(GetTokenTaskParameters getTokenTaskParameters, String str, TaskListener<e> taskListener) {
        super(getTokenTaskParameters, a(str), null, taskListener);
        if (!getTokenTaskParameters.validate()) {
            throw new EsriServiceException("At least one parameter is missing or incorrect. App secret must be set for application logins. ");
        }
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public e execute() throws Exception {
        JsonParser a;
        Map<String, String> generateRequestParams = this.actionInput.generateRequestParams();
        if (((GetTokenTaskParameters) this.actionInput).a()) {
            a = h.b(getServiceURL() + "/oauth2/registerDevice", generateRequestParams);
        } else {
            a = h.a(getServiceURL() + "/oauth2/token", generateRequestParams, false, (n) null);
        }
        e eVar = new e(a);
        a.close();
        return eVar;
    }

    private static String a(String str) {
        return str.contains(IGeneral.PROTO_HTTP_HEAD) ? str.replace(IGeneral.PROTO_HTTP_HEAD, IGeneral.PROTO_HTTPS_HEAD) : str;
    }
}
